using System;

namespace FreeFlow.Client
{	
  /// <summary>A list containing alerts</summary>
  /// <example>
  /// This shows how to populate an ASP.NET DataGrid from an AlertsList object. 
  /// Connection is an already connected <see cref="Connection"/> object.
  /// Populating a WinForms DataGrid is very similar but without a call to DataBind. 
  /// <code language="c#">
  /// AlertsList alertsList = new AlertsList();
  /// alertsList.Connection = Connection;
  /// alertsList.AlertListType = AlertType.ToDo;
  /// alertsList.RefreshItems();
  /// dataGrid.DataSource = alertsList.ListDataTable;
  /// dataGrid.DataBind();
  /// </code>
  /// </example>
  [Serializable]
	public class AlertsList : List
	{
    /// <summary>
    /// Returns the where clause for the engine request for this alert list
    /// </summary>
		protected override string RequestData()
		{
      string sqlFilter = "eAlertType = '" + AlertTypeStr() + "'";
      if ((Filter != null) && (Filter.Length > 0))
        sqlFilter = sqlFilter + " AND " + Filter;
			return "<Where><![CDATA[ " + sqlFilter + " ]]> </Where>";
		}
		
    private string AlertTypeStr()
    {
      return AlertHelper.AlertTypeString(alertListType);
    }
		
    /// <summary>Returns the type of the list needed when caling the engine</summary>
		protected override string ListType()
		{
			return "Alert";
		}
		
		private AlertType alertListType;
    /// <summary>
    /// Gets or sets the alert list type.
    /// </summary>
		public AlertType AlertListType
		{
			get { return alertListType; }
			set { alertListType = value; }
		}

    /// <summary>The column that contains the process name of the alert.</summary>
    public const string ProcessColumn = "eMapName";
    /// <summary>The column that contains the alert subject</summary>
    public const string SubjectColumn = "eSubject";
    /// <summary>The column that contains the alert's updated time</summary>
    public const string UpdatedColumn = "eAlertTime";
    /// <summary>The column that contains the alert's deadline</summary>
    public const string DeadlineColumn = "eDeadline";
    /// <summary>The column that contains the folder ID of the alert.</summary>
    public const string FolderIdColumn = "eFolderID";
    /// <summary>The column that contains the folder name of the alert.</summary>
    public const string FolderNameColumn = "eFolderName";
    /// <summary>The column that contains the stage name of the alert.</summary>
    public const string StageColumn = "eStageName";
    /// <summary>The column that contains the message for the alert.</summary>
    public const string AlertMessageColumn = "eAlertMessage";
    /// <summary>The column that contains the priority of the alert.</summary>
    public const string PriorityColumn = "ePriority";
	}
}
